//*************************************************************************
// pp12-1.java   Author:20172330
//  用递归的方法判断一串字符是否为回文数
//**************************************************************************

import java.util.Scanner;

public class pp12 {
public static void main(String []args) {

    String str, another = "y";
        Scanner scan = new Scanner(System.in);
        while (another.equalsIgnoreCase("y")) {
        System.out.print("Enter a potential palindrome:");
        str = scan.nextLine();
            int i=str.length();
            Boolean b;
            b=diguiPanduan(str,0,i-1);//调用函数
            if(b==true)
            {
                System.out.println("该字符串是回文数");
            }
            else
            {
                System.out.println("该字符串不是回文数");
            }

        System.out.println();
        System.out.println("Test another parlindrome(y/n)?");
        another = scan.nextLine();
         }
        }

public static boolean diguiPanduan(String str, int left, int right)//递归函数{
        if(left==right)
        {
            return true;
        }
        else if(str.charAt(left)==str.charAt(right))
        {
            return diguiPanduan(str,(left+1),(right-1));
        }
        else
        {
            return false;
        }
    }
}
